package cn.edu.scau.cmi.liyunlin.hibernate.dao;

import cn.edu.scau.cmi.liyunlin.hibernate.domain.Major;

import java.util.List;
import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MajorDao extends BaseHibernateDao {

	private static final Logger log = LoggerFactory.getLogger(MajorDao.class);
	// property constants
	public static final String NAME = "name";

	public void save(Major transientInstance) {
		log.debug("saving Major instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Major persistentInstance) {
		log.debug("deleting Major instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Major findById(java.lang.Long id) {
		log.debug("getting Major instance with id: " + id);
		try {
			Major instance = (Major) getSession().get(Major.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public Major merge(Major detachedInstance) {
		log.debug("merging Major instance");
		try {
			Major result = (Major) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Major instance) {
		log.debug("attaching dirty Major instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Major instance) {
		log.debug("attaching clean Major instance");
		try {
			getSession().buildLockRequest(LockOptions.NONE).lock(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	
}
